/*
 *  v4l2cam.h
 *  libCV
 *
 *  Created by Gregory Koch on 14/03/11.
 *  Copyright 2011 IFlyBotIV. All rights reserved.
 *
 */

#ifndef V4L2CAM_H
#define V4L2CAM_H

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <assert.h>

#include <getopt.h>             /* getopt_long() */

#include <time.h>
#include <fcntl.h>              /* low-level i/o */
#include <unistd.h>
#include <errno.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <sys/time.h>
#include <sys/mman.h>
#include <sys/ioctl.h>

#include <linux/videodev2.h>

#include "libCV.h"
#include "ccvt.h"

#define CLEAR(x) memset(&(x), 0, sizeof(x))

#define V4L2_RGB24_640_480 0
#define V4L2_GREY8_640_480 1
#define V4L2_RGB24_320_240 2
#define V4L2_GREY8_320_240 3
#define V4L2_RGB24_160_120 4
#define V4L2_GREY8_160_120 5

struct buffer {
	void   *start;
	size_t  length;
};

typedef struct v4l2cam_s{
	int fdv;
	image_t framebuf;
    unsigned int format;
    struct buffer* buffers;
    unsigned int n_buffers;
    float fps;
    struct timeval tv;
} v4l2cam_t;

v4l2cam_t v4l2cam_open(char* device, unsigned int format);
void v4l2cam_close(v4l2cam_t camera);
void v4l2cam_grab_image(v4l2cam_t *camera);

#endif
